package com.base.cn.platform.os.controller.qa.qareply;

import com.base.cn.platform.os.common.AdminBaseController;
import com.base.cn.platform.os.service.course.qa.qareply.QaReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * 问答评论
 * @author LIZHIPENG
 * @since 2018/4/26
 */
@Controller
@RequestMapping("/admin/qa/reply")
public class AdminQaReplyController extends AdminBaseController {

    @Autowired
    private QaReplyService qaReplyService;

    /**
     * 查询问题评论列表
     * @param model
     * @param currentPage 页码
     * @param params 条件
     * @return
     */
    @RequestMapping("/ajaxQueryQaReplyList")
    public String ajaxQueryQaReplyList(Model model,
                                       @RequestParam(value = "currentPage", required = false, defaultValue = "1") int currentPage,
                                       @RequestBody Map<String, Object> params){
        params.put("parentId",0);
        Map<String, Object> dataMap = qaReplyService.findQaReplyListPage(currentPage,10, params, true, true);
        model.addAttribute("dataMap", dataMap);
        return resultPage("/qa/qareply/ajax-reply");
    }


    @RequestMapping("/ajaxQueryQaReplyAllList")
    @ResponseBody
    public   Map<String, Object> ajaxQueryQaReplyAllList(
            @RequestParam(value = "currentPage", required = false, defaultValue = "1") int currentPage,
            @RequestParam("parentId") BigDecimal parentId,@RequestParam("pageSize") int pageSize){
        Map<String, Object> params = new HashMap<>();
        params.put("parentId",parentId);
        return    qaReplyService.findQaReplyListPage(currentPage,pageSize, params, true, true);
    }
}
